package com.xxy.book.controller;

import com.xxy.book.entity.Book;
import com.xxy.book.entity.Page;
import com.xxy.book.service.BookService;
import com.xxy.book.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Author Xu XianYun
 * @Date 2022-12-25
 * @Description
 */
@RestController
@RequestMapping("/book")
public class BookHandler {

    @Resource
    private BookService bookService;

    @GetMapping("/findAll")
    public Result<List<Book>> findAllBooks(Page page) {
        return Result.ok(bookService.findAllBooks(0, 5));
    }

    @PostMapping("/add")
    public Result addBook(Book book) {
        book.setCreateTime(new Date());
        return bookService.addBook(book);
    }
}
